package cn.com.my.yes1;

import java.util.ArrayList;
import java.util.List;

import com.thoughtworks.xstream.XStream;

import cn.com.my.vo.Classes;
import cn.com.my.vo.Hbinfo;
import cn.com.my.vo.Student;
import cn.com.my.vo.RedPackInfoReturn;

public class TestXmlTx {

	public static void main(String[] args) {
		XStream xStream = new XStream(); 
		xStream.autodetectAnnotations(true);  
		
		Classes c = new Classes();
		c.setClsName("c1");
		c.setDetail_id("CNM");
		c.setNum(100);
		
		Student s = new Student();
		s.setName_to("joe");
		s.setReturn_code("ABCD");
		s.setSex(1);
		s.setAge(29);
		
		ArrayList<Student> stus = new ArrayList<Student>();
		stus.add(s);
		c.setStus(stus);
		
		 
        
        String xml = xStream.toXML(c);  
        System.out.println(xml);  
		/*
        String rs = "<xml>"
		+"  <clsName>c1</clsName>"
        +" <detail__id>CNM</detail__id>"
		+"  <num>100</num>"
		+"  <stus>"
		+"    <student>"
		+"      <name__to>joe</name__to>"
		+"		<return__code><![CDATA[ABCD]]></return__code>"
		+"      <sex>1</sex>"
		+"      <age>29</age>"
		+"    </student>"
		+"  </stus>"
		+"</xml>";
        
        Classes xc = (Classes)xStream.fromXML(rs);
        System.out.println(xc.toString());*/
       
        
		RedPackInfoReturn red = new RedPackInfoReturn();
		red.setResult_code("SUCCESS");
		red.setReturn_msg("获取成功");
		red.setResult_code("SUCCESS");
        red.setMch_id("1241743402");
        red.setAppid("wx1fc8de6e9765b775");
		red.setOpenid("oAiG2juhpkJw3Uha_FqmCyQKdV4E");
		red.setDetail_id("0010213132201510220265831458");
		red.setMch_billno("201510221416368004");
		red.setStatus("RECEIVED");
		red.setSend_type("API");
		red.setHb_type("NORMAL");
		red.setTotal_num(1);
		red.setTotal_amount(101);
		red.setSend_time("2015-10-22 14:57:20");
		red.setWishing("只有抢，才有得~");
		red.setRemark("齐力堂管家班总结会");
		red.setAct_name("齐力堂管家班抢红包");
		
		Hbinfo hb = new Hbinfo();
		hb.setOpenid("oAiG2juhpkJw3Uha_FqmCyQKdV4E");
		hb.setStatus("RECEIVED");
		hb.setAmount(101);
		hb.setRcv_time("2015-10-22 14:57:45");
		
		List<Hbinfo> hblist = new ArrayList<Hbinfo>();
		hblist.add(hb);
		red.setHblist(hblist);
		
		String xmlStr = xStream.toXML(red);
		System.out.println(xmlStr);
		
		
		
        String rs2 = "<xml>"
        		+"<return_code><![CDATA[SUCCESS]]></return_code>"
        		+"<return_msg><![CDATA[获取成功]]></return_msg>"
        		+"<result_code><![CDATA[SUCCESS]]></result_code>"
        		+"<mch_id>1241743402</mch_id>"
        		+"<appid><![CDATA[wx1fc8de6e9765b775]]></appid>"
        		+"<openid><![CDATA[oAiG2juhpkJw3Uha_FqmCyQKdV4E]]></openid>"
        		+"<detail_id><![CDATA[0010213132201510220265831458]]></detail_id>"
        		+"<mch_billno><![CDATA[201510221416368004]]></mch_billno>"
        		+"<status><![CDATA[RECEIVED]]></status>"
        		+"<send_type><![CDATA[API]]></send_type>"
        		+"<hb_type><![CDATA[NORMAL]]></hb_type>"
        		+"<total_num>1</total_num>"
        		+"<total_amount>101</total_amount>"
        		+"<send_time><![CDATA[2015-10-22 14:57:20]]></send_time>"
        		+"<wishing><![CDATA[只有抢，才有得~]]></wishing>"
        		+"<remark><![CDATA[齐力堂管家班总结会]]></remark>"
        		+"<act_name><![CDATA[齐力堂管家班抢红包]]></act_name>"
        		+"<hblist>"
        		+"<hbinfo>"
        		+"<openid><![CDATA[oAiG2juhpkJw3Uha_FqmCyQKdV4E]]></openid>"
        		+"<status><![CDATA[RECEIVED]]></status>"
        		+"<amount>101</amount>"
        		+"<rcv_time><![CDATA[2015-10-22 14:57:45]]></rcv_time>"
        		+"</hbinfo>"
        		+"</hblist>"
        		+"</xml>";
        
        
        RedPackInfoReturn ri = (RedPackInfoReturn)xStream.fromXML(rs2);
        System.out.println(ri.toString());
        
        
	}

}
